<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <!--<meta charset="UTF-8">-->
    <title>首页</title>
    <script src="../static/jQuery/jquery-2.2.3.min.js"></script>
    <script src="../static/layer/layer.js"></script>
    <script src="../static/angularjs/angular.min.js"></script>

    <script>
        // var user_id = document.getElementById('userid').value;
        // var user_id = $('#userid').val();


        var app = angular.module("indexApp", []);
        //绑定控制器
        app.controller("indexController", function ($scope, $http) {
            $scope.findAll = function () {
                $http.get("address/list").success(function (resp) {
                    $scope.list = resp;

                })
            };

            $scope.findById = function () {
                // console.log($scope.userid);
                console.log("findByID________选择器获得value的值:" + $('#userid').val());

                $http.post("address/findById/" + $('#userid').val()).success(function (resp) {
                    $scope.schoolID = resp.collegelcationid;
                    $scope.address = resp.address;
                    $scope.username = resp.name;
                    $scope.phone = resp.mobile;
                    //手机号
                })
            };

            $scope.update = function () {
                // console.log($scope.userid);
                console.log("update________id选择器获得value的值:" + $('#userid').val());

                $http.post("address/update/" + $('#userid').val()).success(function (resp) {
                    $scope.schoolID = resp.collegelcationid;
                    $scope.address = resp.address;
                    $scope.username = resp.name;
                    $scope.phone = resp.mobile;
                    //手机号
                })
            };

            $scope.delete = function () {
                // console.log($scope.userid);
                console.log("delete____id选择器获得value的值:" + $scope.id/* $('#userid').val()*/);

                $http.post("address/del/" + $scope.id /*$('#userid').val()*/).success(function (resp) {
                    $scope.schoolID = resp.collegelcationid;
                    $scope.address = resp.address;
                    $scope.username = resp.name;
                    $scope.phone = resp.mobile;
                    //手机号
                })
            };


        });


        //修改方法
           function update() {
               //弹出层
               layer.open({
                   type: 1,
                   area: ['500px', '600px'],
                   title: '地址修改'
                   , content: $("#test"),
                   shade: 0,
                   btn: ['修改', '取消 ']
                   , btn1: function (index, layero) {

                       alert("修改成功");

                   },
                   btn2: function (index, layero) {
                       alert("是否取消修改");
                       return true;
                   },
                   cancel: function (layero, index) {
                       layer.closeAll();
                   }

               });

           }

        function jump() {
            $.get("/form", function (date) {
                console.log(date);
            }, "html");
        }

    </script>
</head>
<body ng-app="indexApp" ng-controller="indexController" ng-init="findAll()">
<input type="hidden" value="查询" onclick="findAll()"/>
<h4>地址信息</h4>
<div>
    <div>

        <table>
            <tr>
                <th>学号</th>
                <th>地址</th>
                <th>名字</th>
                <th>电话</th>
            </tr>
            <tr id="content" ng-repeat="a in list">
                <input id="userid" ng-model="id" value={{a.id}} type="hidden"/>
                <td id="collegeLcationID">{{a.collegelcationid}}</td>
                <td id="addres">{{a.address}}</td>
                <td id="name">{{a.name}}</td>
                <td id="module">{{a.mobile}}</td>
                <td id="up"><input type='button' ng-model='userid' value='修改' ng-click="update()" onclick='update()'/>
                </td>
                <td id="dele"><input type='button' ng-model='userid' value='删除' ng-click="delete()" onclick="delete()"/>
                </td>

            </tr>
        </table>

    </div>

    <br/>
    <div>
        <div>
            <from id="add">
                学 号: <input type="text" ng-model="schoolID" value="请输入学号"><br/>
                地 址: <input type="text" ng-model="address" value="请输入地址"> <br/>
                姓 名: <input type="text" ng-model="username" value="请输入姓名"><br/>
                手 机 号: <input type="text" ng-model="phone" value="请输入手机号"><br/>
                <input type="button" value="添加"><br/>

            </from>
        </div>
    </div>
    <div>
        <div>
            <form class="layui-form" id="test" style="display:none">
                <div class="layui-form-item">
                    <label class="layui-form-label">学号</label>
                    <div class="layui-input-block">
                        <input type="text" name="collegeLcationid" ng-model="schoolID" required lay-verify="required"
                               placeholder="请输入标题"
                               autocomplete="on"
                               class="layui-input" style="width:100px">
                    </div>
                </div>


                <div class="layui-form-item">
                    <label class="layui-form-label">地址</label>
                    <div class="layui-input-inline">
                        <input type="text" name="address" ng-model="address" required lay-verify="required"
                               placeholder=""
                               autocomplete="on"
                               class="layui-input">

                    </div>
                </div>

                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">姓名</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" ng-model="username" placeholder="请输入内容" class="layui-textarea"/>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">手机号</label>
                    <div class="layui-input-inline">
                        <input type="text" name="module" ng-model="phone" required lay-verify="required"
                               placeholder="请输入手机号" autocomplete="on"
                               class="layui-input">
                    </div>
                </div>
            </form>
            <input type="hidden" id="div" ng-click="findById()" onclick="findById()"/>
        </div>
    </div>

    <!--<input type="button" href="templates/order.html" onclick="jump()" value="查看所有订单"/>-->


    <div>
        <form th:action="@{/form}" method="post" enctype="multipart/form-data">
            <input type="submit">
        </form>
       <!-- <form action="/th/order" method="post" enctype="multipart/form-data">
            <input type="submit">
        </form>-->
    </div>

</div>

</body>
</html>